package cn.xc.system.controller;


import cn.xc.basic.util.AjaxResult;
import cn.xc.basic.util.PageList;
import cn.xc.system.domain.Systemdictionarytype;
import cn.xc.system.query.SystemdictionarytypeQuery;
import cn.xc.system.service.ISystemdictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdictionarytype")
public class SystemdictionarytypeController {

    @Autowired
    private ISystemdictionarytypeService systemdictionarytypeSeriver;

    @GetMapping("/{id}")
    public Systemdictionarytype loadById(@PathVariable("id") Long id){
        return systemdictionarytypeSeriver.loadById(id);
    }

    @GetMapping
    public List<Systemdictionarytype> loadAll(){
        return systemdictionarytypeSeriver.loadAll();
    }

    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id){
        try {
            systemdictionarytypeSeriver.remove(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarytype systemdictionarytype){
        try {
            if (systemdictionarytype.getId()==null){
                systemdictionarytypeSeriver.save(systemdictionarytype);
            }else {
                systemdictionarytypeSeriver.update(systemdictionarytype);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    @PostMapping
    public PageList<Systemdictionarytype> queryPage(@RequestBody SystemdictionarytypeQuery systemdictionarytypeQuery){
            return systemdictionarytypeSeriver.queryPage(systemdictionarytypeQuery);
    }

    @PatchMapping
    public AjaxResult patchRemove(@RequestBody List<Long> ids){
        try {
            systemdictionarytypeSeriver.patchRemove(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }


}
